﻿using ValidationEngine.Commons;
using ValidationEngine.Commons.Enums;
using ValidationEngine.Commons.Interfaces;

namespace ValidationEngine.Commons
{
    /// <summary>
    /// Model with validation information interface
    /// </summary>
    public interface IValidateableModel
    {
        /// <summary>
        /// Event raised to validate model's property changes.
        /// </summary>
        event PropertyValidationEventHandler PropertyValidating;
        
        /// <summary>
        /// Validates model (raises PropertyValidating event for all properties).
        /// </summary>
        void ReValidate(RuleApplingContext ctx);

        /// <summary>
        /// Clears internal validation info cache.
        /// </summary>
        void ClearAllValidations();

        /// <summary>
        /// Clears internal validation info cache for property
        /// </summary>
        /// <param name="propertyName">Property name.</param>
        void ClearPropertyValidationInfo(string propertyName);

        /// <summary>
        /// Sets property validation info
        /// </summary>
        /// <param name="propertyName">Property name.</param>
        /// <param name="info">Validation info.</param>
        void SetPropertyValidationInfo(string propertyName, IValidationInfo info);

        /// <summary>
        /// Reads property validation info
        /// </summary>
        /// <param name="propertyName">Property name.</param>
        /// <returns>Validation info.</returns>
        IValidationInfo GetPropertyValidationInfo(string propertyName);

        /// <summary>
        /// Indicates if model has errors
        /// </summary>
        bool IsValid { get; }
    }
}
